<?php
class ECPaging
{
    static $page_current = "";

    static function pagingSE(&$limit = false, $totalitem, $itemperpage, $numpageshow = 10, $page_name = 'page_no', $show_total_item = false, $itemname = '', $page_label = '', $mod = false)
    {
        $st = '';
        $totalpage = ceil($totalitem / $itemperpage);
        if ($totalpage < 2) {
            if ($show_total_item) {
                return '<b>Tổng số ' . number_format($totalitem, 0, '', '.') . '</b> ' . $itemname;
            }
            return;
        }

        if (Url::get($page_name)) {
            $currentpage = Url::get($page_name);
        } else {
            $currentpage = 1;
        }

        $currentpage = round($currentpage);
        if ($currentpage <= 0 || $currentpage > $totalpage) {
            $currentpage = 1;
        }

        $limit = ' LIMIT ' . (($currentpage - 1) * $itemperpage) . ',' . $itemperpage;

        if ($currentpage > ($numpageshow / 2)) {
            $startpage = $currentpage - floor($numpageshow / 2);
            if ($totalpage - $startpage < $numpageshow) {
                $startpage = $totalpage - $numpageshow + 1;
            }
        } else {
            $startpage = 1;
        }
        if ($startpage < 1) {
            $startpage = 1;
        }

        //$url_path = Url::build_all(array($page_name));
        $host = $_SERVER['HTTP_HOST'];
        $self = $_SERVER['PHP_SELF'];
        $query = !empty($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : null;
        $url_path = !empty($query) ? "http://$host$self?$query" : "http://$host$self";


        //Trang hien thoi
        $st .= '' . ($show_total_item ? '<b>Tổng số ' . number_format($totalitem, 0, '', '.') . ' ' . $itemname . '</b> | ' : '') . '' . $page_label . ' ';
        //Link den trang truoc
        if ($currentpage > 1) {
            $st .= '<a href="' . $url_path . (strpos($url_path, '?') === false ? '?' : '&') . $page_name . '=' . ($currentpage - 1) . '" class="pgPrev">';
            $st .= 'Trước</a>';
        }

        //Danh sach cac trang
        $st .= '';

        if ($startpage > 1) {
            //$st .= '<a href="'.$url_path.(strpos($url_path, '?')===false?'?':'&').$page_name.'='.$currentpage.'" id="pgNext">';
            $st .= '<a  href="' . $url_path . '">1</a> ';
            if ($startpage > 2) {
                $st .= '<strong>...</strong>'; //
            }
        }

        for ($i = $startpage; $i <= $startpage + $numpageshow - 1 && $i <= $totalpage; $i++) {
            if ($i != $startpage) {
                $st .= ''; //
            }
            if ($i == $currentpage) {
                if ($i > 1) {
                    $st .= '';
                }
                $st .= '<a href="javascript:void(0)" class="pgCurrent" id="pgCurrent">' . $i . '</a>';
            } else {
                if ($i > 1) {
                    $st .= '';
                }
                $st .= '<a  href="' . $url_path . (strpos($url_path, '?') === false ? '?' : '&') . $page_name . '=' . $i . '">' . $i . '</a> ';
            }
        }

        if ($i == $totalpage) {
            $st .= '<a  href="' . $url_path . (strpos($url_path, '?') === false ? '?' : '&') . $page_name . '=' . $totalpage . '">' . $totalpage . '</a> ';
        } else
            if ($i < $totalpage) {
                $st .= '<strong>...</strong><a  href="' . $url_path . (strpos($url_path, '?') === false ? '?' : '&') . $page_name . '=' . $totalpage . '">' . $totalpage . '</a> ';
            }
        $st .= '';
        //Trang sau
        if ($currentpage < $totalpage) {
            $st .= '<a  href="' . $url_path . (strpos($url_path, '?') === false ? '?' : '&') . $page_name . '=' . ($currentpage + 1) . '" class="pgPrev">';
            $st .= 'Sau</a>';
        }

        $st .= '';

        $st = ECRewrite::formatUrl($st);
        return "<div class=\"product-list-paging\">$st</div>";
    }

    /**
    <div class="paging-hotel">
    <a href="#">Đầu</a>
    <a href="#">«</a>
    <a href="#">1</a>
    <a href="#">2</a>
    <a href="#" class="current">3</a>
    <a href="#">4</a>
    <a href="#">5</a>
    <a href="#">6</a>
    <a href="#">»</a>
    <a href="#">Cuối</a>
    </div>
     */

    static function pagingLocation(&$limit = false, $totalitem, $itemperpage, $numpageshow = 10, $page_name = 'page-no', $show_total_item = false, $itemname = '', $url = '', $page_no = 1, $mod = false)
    {
        $st = '';
        $totalpage = ceil($totalitem / $itemperpage);
        if ($totalpage < 2) {
            if ($show_total_item) {
                return '';
            }
            return;
        }

        if (Url::get($page_name)) {
            $currentpage = Url::get($page_name);
        } else {
            $currentpage = $page_no;
        }

        $currentpage = round($currentpage);
        if ($currentpage <= 0 || $currentpage > $totalpage) {
            $currentpage = 1;
        }

        $limit = ' LIMIT ' . (($currentpage - 1) * $itemperpage) . ',' . $itemperpage;

        if ($currentpage > ($numpageshow / 2)) {
            $startpage = $currentpage - floor($numpageshow / 2);
            if ($totalpage - $startpage < $numpageshow) {
                $startpage = $totalpage - $numpageshow + 1;
            }
        } else {
            $startpage = 1;
        }
        if ($startpage < 1) {
            $startpage = 1;
        }
        if ($url == '') {
            $url_path = Url::build_all(array($page_name));
        } else {
            $url_path = WEB_ROOT . $url;
        }


        //Trang hien thoi
        // $st .= ''.($show_total_item?'<b>Tổng số '.number_format($totalitem, 0, '', '.').' '.$itemname.'</b> | ':'').''.$page_label.' ';
        //Link den trang truoc
        if ($currentpage > 1) {
            $st .= '<a href="javascript:;" data-page="' . ($currentpage - 1) . '" class="page-number btn-prev sys-paging-location">';
            $st .= '<img class="icon iBtnPrev" src="style/images/frontend/blank.gif" ></a>';

            /*$st .= '<a href="javascript:;" data-page="' . ($currentpage - 1) . '" class="pgPrev sys-paging-location">';
            $st .= 'Trước</a>';*/
        }

        //Danh sach cac trang
        $st .= '';

        if ($startpage > 1) {
            //$st .= '<a href="'.$url_path.(strpos($url_path, '?')===false?'?':'&').$page_name.'='.$currentpage.'" id="pgNext">';
            $st .= '<a  href="javascript:;" data-page="1" class="sys-paging-location page-number">1</a> ';
            /*if ($startpage > 2) {
                $st .= '<span class="page-number">...</span>'; //
            }*/
        }


        for ($i = $startpage; $i <= $startpage + $numpageshow - 1 && $i <= $totalpage; $i++) {
            if ($i != $startpage) {
                $st .= ''; //
            }
            if ($i == $currentpage) {
                if ($i > 1) {
                    $st .= '';
                }
                $st .= '<a href="javascript:;" class="pgCurrent active sys-paging-location page-number" id="pgCurrent" data-page="' . $i . '">' . $i . '</a>';
            } else {
                if ($i > 1) {
                    $st .= '';
                }
                $st .= '<a  href="javascript:;" data-page="' . $i . '" class="sys-paging-location page-number">' . $i . '</a> ';
            }

               /* if($i > 3){
                    break;
                }*/

        }

        if ($i == $totalpage) {
            $st .= '<a  href="javascript:;" class="sys-paging-location page-number" data-page="' . $totalpage . '">' . $totalpage . '</a> ';
        } else
            if ($i < $totalpage) {
                //$st .= '<span class="page-number">...</span><a  href="javascript:;" class="sys-paging-location page-number" data-page="' . $totalpage . '">' . $totalpage . '</a> ';
                //$st .= '<a  href="javascript:;" data-page="' . $currentpage +1 . '" class="sys-paging-location page-number">' . $currentpage+1 . '</a> ';
                $st .= '<a  href="javascript:;" class="sys-paging-location page-number" data-page="' . $totalpage . '">' . $totalpage . '</a> ';
            }
        $st .= '';
        //Trang sau
        if ($currentpage < $totalpage) {
            /*$st .= '<a  href="javascript:;" data-page="' . ($currentpage + 1) . '" class="pgPrev sys-paging-location">';
            $st .= 'Sau</a>';*/

            $st .= '<a href="javascript:;" data-page="' . ($currentpage + 1) . '" class="page-number btn-next sys-paging-location"><img class="icon iBtnNext" src="style/images/frontend/blank.gif" ></a>';

        }

        $st .= '';

        $st = ECRewrite::formatUrl($st);
        return "<div class=\"common-paging sys-paging-location-hotel\">$st</div>";
    }

    static function paging(&$limit = false, $totalitem, $itemperpage, $numpageshow = 10, $page_name = 'page_no', $show_total_item = false, $itemname = '', $page_label = '', $mod = false)
    {
        $totalpage = ceil($totalitem / $itemperpage);
        if ($totalpage < 2) {
            return;
        }
        if (Url::get($page_name)) {
            $currentpage = Url::get($page_name);
        } else {
            $currentpage = 1;
        }

        $currentpage = round($currentpage);
        if ($currentpage <= 0 || $currentpage > $totalpage) {
            $currentpage = 1;
        }

        $limit = ' LIMIT ' . (($currentpage - 1) * $itemperpage) . ',' . $itemperpage;

        if ($currentpage > ($numpageshow / 2)) {
            $startpage = $currentpage - floor($numpageshow / 2);
            if ($totalpage - $startpage < $numpageshow) {
                $startpage = $totalpage - $numpageshow + 1;
            }
        } else {
            $startpage = 1;
        }
        if ($startpage < 1) {
            $startpage = 1;
        }

        if (strpos(Url::build_all(array($page_name)), "?") !== false) {
            $url_path = Url::build_all(array($page_name)) . '&' . $page_name . '=';
        } else {
            $url_path = Url::build_all(array($page_name)) . '?' . $page_name . '=';
        }

        //Link den trang truoc
        if ($currentpage > 1) {
            $st = '<div class="pag_bg floatLeft" onmouseout="this.className=\'pag_bg floatLeft\'" onmouseover="this.className=\'pag_bg_hover floatLeft\'">
						<div class="pag_left_pre">
							<div class="pag_right_pre">
								<a href=\'' . $url_path . ($currentpage - 1) . '\'>Trước</a>
							</div>
						</div>
					</div>';
        } else {
            $st = '<div class="pag_bg_dis floatLeft ">
			<div class="pag_left_pre_dis">
				<div class="pag_right_pre_dis">
					Trước
				</div>
			</div>

			 </div>';
        }
        //Danh sach cac trang
        if ($startpage > 1) {
            $st .= '<div class="floatLeft  pag_bg" onmouseover="javascript:this.className=\'floatLeft  pag_bg_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg\'">
							<div class="pag_left">
								<div class="pag_right">
									<a  href="' . $url_path . '1">1</a>
								</div>
							</div>
						</div>
					';
            if ($startpage > 2) {
                //$st .= '<div class="floatLeft marginLeft5" style="border:1px solid #f00"><strong>...</strong></div>';

                $st .= '<div class="floatLeft  pag_bg">
							<div class="pag_left">
								<div class="pag_right_dot">
									...
								</div>
							</div>
						</div>';
            }
        }

        for ($i = $startpage; $i <= $startpage + $numpageshow - 1 && $i <= $totalpage; $i++) {
            /*if($i!=$startpage){$st .= '';}*/
            if ($i == $currentpage) {
                /*if($i>1){$st .='';}*/
                $st .= '<div class="floatLeft  pag_bg_hover">
							<div class="pag_left">
								<div class="pag_right">
									<a href="javascript:void(0);">' . $i . '</a>
								</div>
							</div>
						</div>';
            } else {
                /*if($i>1){$st .='';}*/
                $st .= '<div class="floatLeft  pag_bg" onmouseover="javascript:this.className=\'floatLeft  pag_bg_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg\'">
							<div class="pag_left">
								<div class="pag_right">
									<a  href="' . $url_path . $i . '">' . $i . '</a>
								</div>
							</div>
						</div>';
            }
        }
        if ($i == $totalpage) {
            $st .= '<div class="floatLeft  pag_bg" onmouseover="javascript:this.className=\'floatLeft  pag_bg_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg\'">
							<div class="pag_left">
								<div class="pag_right">
									<a  href="' . $url_path . $totalpage . '">' . $totalpage . '</a>
								</div>
							</div>
						</div>';

        } elseif ($i < $totalpage) {
            $st .= '<div class="floatLeft  pag_bg">
							<div class="pag_left">
								<div class="pag_right_dot">
									...
								</div>
							</div>
						</div>
					<div class="floatLeft  pag_bg" onmouseover="javascript:this.className=\'floatLeft  pag_bg_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg\'">
							<div class="pag_left">
								<div class="pag_right">
									<a  href="' . $url_path . $totalpage . '">' . $totalpage . '</a>
								</div>
							</div>
						</div>';
        }
        //Trang sau
        if ($currentpage < $totalpage) {
            $st .= '<div class="pag_bg floatLeft " onmouseout="this.className=\'pag_bg floatLeft \'" onmouseover="this.className=\'pag_bg_hover floatLeft \'">
			<div class="pag_left_next">
				<div class="pag_right_next">
					<a href=\'' . $url_path . ($currentpage + 1) . '\'>Sau</a>
				</div>
			</div>
			</div>';
        } else {
            $st .= '<div class="pag_bg_dis floatLeft ">
						<div class="pag_left_next_dis">
							<div class="pag_right_next_dis">
								Sau
							</div>
						</div>
			 </div>';
        }

        $st = ECRewrite::formatUrl($st);
        return $st;
    }

    static function paging_next(&$limit = false, $itemperpage, $page_next = true, $page_name = 'page_no')
    {
        if (Url::get($page_name)) {
            $currentpage = (int)Url::get($page_name, 0);
        } else {
            $currentpage = 1;
        }

        if ($currentpage <= 0) {
            $currentpage = 1;
        }

        $limit = ' LIMIT ' . (($currentpage - 1) * $itemperpage) . ',' . ($itemperpage + 1);

        $url_path = Url::build_all(array($page_name)) . '&' . $page_name . '=';

        //Link den trang truoc
        if ($currentpage > 1) {
            $st = '<div class="pag_bg floatLeft" onmouseout="this.className=\'pag_bg floatLeft\'" onmouseover="this.className=\'pag_bg_hover floatLeft\'">
						<div class="pag_left_pre">
							<div class="pag_right_pre">
								<a href=\'' . $url_path . ($currentpage - 1) . '\'>Trước</a>
							</div>
						</div>
					</div>';
        } else {
            $st = '<div class="pag_bg_dis floatLeft ">
			<div class="pag_left_pre_dis">
				<div class="pag_right_pre_dis">
					Trước
				</div>
			</div>

			 </div>';
        }

        //Trang sau
        if ($page_next) {
            $st .= '<div class="pag_bg floatLeft " onmouseout="this.className=\'pag_bg floatLeft \'" onmouseover="this.className=\'pag_bg_hover floatLeft \'">
			<div class="pag_left_next">
				<div class="pag_right_next">
					<a href=\'' . $url_path . ($currentpage + 1) . '\'>Sau</a>
				</div>
			</div>
			</div>';
        } else {
            $st .= '<div class="pag_bg_dis floatLeft ">
						<div class="pag_left_next_dis">
							<div class="pag_right_next_dis">
								Sau
							</div>
						</div>
			 </div>';
        }

        return $st;
    }

    static function paging_new(&$limit = false, $totalitem, $itemperpage, $page_name = 'page_no', $url_new = '', $show_total_item = false, $itemname = '', $page_label = '', $mod = false)
    {
        $totalpage = ceil($totalitem / $itemperpage);
        if ($totalpage < 2) {
            return;
        }

        if (Url::get($page_name)) {
            $currentpage = Url::get($page_name);
        } else {
            $currentpage = 1;
        }

        $currentpage = round($currentpage);
        if ($currentpage <= 0 || $currentpage > $totalpage) {
            $currentpage = 1;
        }

        $limit = ' LIMIT ' . (($currentpage - 1) * $itemperpage) . ',' . $itemperpage;

        if ($currentpage > 3) {
            $startpage = $currentpage - 3;

            if ($totalpage - $startpage < 7) {
                $startpage = $totalpage - 7 + 1;
            }
        } else {
            $startpage = 1;
        }
        if ($startpage < 1) {
            $startpage = 1;
        }

        /*$startpage = $currentpage-3;

		if($totalpage-$startpage<7){
			$startpage=$totalpage-7+1;
		}*/

        if ($url_new) {
            $url_path = $url_new . '&' . $page_name . '=';
        } else {
            $url_path = Url::build_all(array($page_name)) . '&' . $page_name . '=';
        }

        //Link den trang truoc
        if ($currentpage > 1) {
            $paging_str = '<div class="pag_bg floatLeft" onmouseout="this.className=\'pag_bg floatLeft\'" onmouseover="this.className=\'pag_bg_hover floatLeft\'">
						<div class="pag_left_pre">
							<div class="pag_right_pre">
								<a href=\'' . $url_path . ($currentpage - 1) . '\'>Trước</a>
							</div>
						</div>
					</div>';
        } else {
            $paging_str = '<div class="pag_bg_dis floatLeft ">
			<div class="pag_left_pre_dis">
				<div class="pag_right_pre_dis">
					Trước
				</div>
			</div>

			 </div>';
        }

        //Danh sach cac trang

        if ($startpage > 1) {
            $paging_str .= '<div class="floatLeft  pag_bg" onmouseover="javascript:this.className=\'floatLeft  pag_bg_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg\'">
							<div class="pag_left">
								<div class="pag_right">
									<a  href="' . $url_path . '1">1</a>
								</div>
							</div>
						</div>';
        }
        if ($startpage > 2) {
            $paging_str .= '<div class="floatLeft  pag_bg" onmouseover="javascript:this.className=\'floatLeft  pag_bg_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg\'">
							<div class="pag_left">
								<div class="pag_right">
									<a  href="' . $url_path . '2">2</a>
								</div>
							</div>
						</div>';
        }
        if ($startpage > 3) {
            $paging_str .= '<div class="floatLeft  pag_bg" onmouseover="javascript:this.className=\'floatLeft  pag_bg_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg\'">
							<div class="pag_left">
								<div class="pag_right">
									<a  href="' . $url_path . '3">3</a>
								</div>
							</div>
						</div>';
        }

        if ($startpage > 4) {
            $paging_str .= '<div class="floatLeft  pag_bg">
						<div class="pag_left">
							<div class="pag_right_dot">
								...
							</div>
						</div>
					</div>';
        }


        for ($i = $startpage; $i <= $startpage + 6 && $i <= $totalpage; $i++) {
            //if($i>=1 && (($currentpage==1 && $i<4) || $currentpage>1))
            {
                if ($i == $currentpage) {
                    $paging_str .= '<div class="floatLeft pag_bg_hover pag_bg_current">
								<div class="pag_left">
									<div class="pag_right">
										<a href="javascript:void(0);">' . $i . '</a>
									</div>
								</div>
							</div>';
                } else {
                    $paging_str .= '<div class="floatLeft  pag_bg" onmouseover="javascript:this.className=\'floatLeft  pag_bg_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg\'">
								<div class="pag_left">
									<div class="pag_right">
										<a  href="' . $url_path . $i . '">' . $i . '</a>
									</div>
								</div>
							</div>';
                }
            }
        }

        if ($i <= 8 && $totalpage >= 8) {
            $paging_str .= '<div class="floatLeft  pag_bg" onmouseover="javascript:this.className=\'floatLeft  pag_bg_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg\'">
								<div class="pag_left">
									<div class="pag_right">
										<a  href="' . $url_path . '8">8</a>
									</div>
								</div>
							</div>';
            $i++;
        }

        if ($i <= 9 && $totalpage >= 9) {
            $paging_str .= '<div class="floatLeft  pag_bg" onmouseover="javascript:this.className=\'floatLeft  pag_bg_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg\'">
							<div class="pag_left">
								<div class="pag_right">
									<a  href="' . $url_path . '9">9</a>
								</div>
							</div>
						</div>';
            $i++;
        }

        if ($i <= 10 && $totalpage >= 10) {
            $paging_str .= '<div class="floatLeft  pag_bg" onmouseover="javascript:this.className=\'floatLeft  pag_bg_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg\'">
							<div class="pag_left">
								<div class="pag_right">
									<a  href="' . $url_path . '10">10</a>
								</div>
							</div>
						</div>';
            $i++;
        }

        if ($i == $totalpage) {
            $paging_str .= '<div class="floatLeft  pag_bg" onmouseover="javascript:this.className=\'floatLeft  pag_bg_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg\'">
							<div class="pag_left">
								<div class="pag_right">
									<a  href="' . $url_path . $totalpage . '">' . $totalpage . '</a>
								</div>
							</div>
						</div>';

        } elseif ($i < $totalpage) {
            $paging_str .= '<div class="floatLeft  pag_bg">
							<div class="pag_left">
								<div class="pag_right_dot">
									...
								</div>
							</div>
						</div>';
        }

        //Trang sau
        if ($currentpage < $totalpage) {
            $paging_str .= '<div class="pag_bg floatLeft " onmouseout="this.className=\'pag_bg floatLeft \'" onmouseover="this.className=\'pag_bg_hover floatLeft \'">
			<div class="pag_left_next">
				<div class="pag_right_next">
					<a href=\'' . $url_path . ($currentpage + 1) . '\'>Sau</a>
				</div>
			</div>
			</div>';
        } else {
            $paging_str .= '<div class="pag_bg_dis floatLeft ">
						<div class="pag_left_next_dis">
							<div class="pag_right_next_dis">
								Sau
							</div>
						</div>
			 		</div>';
        }

        return $paging_str;
    }

    static function paging_list(&$limit = false, $itemperpage, $page_name = 'page_no', $url_path = '')
    {
        $currentpage = (int)Url::get($page_name);

        if ($currentpage <= 0) {
            $currentpage = 1;
        } elseif ($currentpage > 200) {
            $currentpage = 200;
        }

        if ($currentpage <= 6) {
            $totalpage = 11;
        } else {
            $totalpage = ($currentpage + 4) < 200 ? ($currentpage + 4) : 200;
        }

        $limit = ' LIMIT ' . (($currentpage - 1) * $itemperpage) . ',' . $itemperpage;

        if ($currentpage > 3) {
            $startpage = $currentpage - 3;

            if ($totalpage - $startpage < 7) {
                $startpage = $totalpage - 7 + 1;
            }
        } else {
            $startpage = 1;
        }

        if ($startpage < 1) {
            $startpage = 1;
        }

        if ($url_path == '') {
            $url_path = Url::build_all(array($page_name));
        }

        //Link den trang truoc
        if ($currentpage > 1) {
            $paging_str = '<div class="paging_bg floatLeft" onmouseout="this.className=\'paging_bg floatLeft\'" onmouseover="this.className=\'paging_bg_hover floatLeft\'">
						<div class="paging_pre">
							<a href=\'' . $url_path . ($currentpage > 2 ? '&' . $page_name . '=' . ($currentpage - 1) : '') . '\'>&laquo; Trước</a>
						</div>
					</div>';
        } else {
            $paging_str = '<div class="paging_bg_dis floatLeft ">
							<div class="paging_pre_dis">
									&laquo; Trước
							</div>
			 				</div>';
        }

        //Danh sach cac trang

        $i = 1;
        while ($i <= 4) {
            if ($startpage > $i) {
                if ($i < 4) {
                    $paging_str .= '<div class="floatLeft  paging_bg" onmouseover="javascript:this.className=\'floatLeft  paging_bg_hover\'" onmouseout="javascript:this.className=\'floatLeft  paging_bg\'">
                                    <div class="paging_node">
                                        <a  href="' . $url_path . ($i > 1 ? '&' . $page_name . '=' . $i : '') . '">' . $i . '</a>
                                    </div>
                            </div>';
                } else {
                    $paging_str .= '<div class="floatLeft  paging_bg">
                                <div class="paging_node_dot">
                                    ...
                                </div>
                        </div>';
                }
            }
            $i++;
        }

        for ($i = $startpage; $i <= $startpage + 6 && $i <= $totalpage; $i++) {
            if ($i == $currentpage) {
                $paging_str .= '<div class="floatLeft paging_bg_hover paging_bg_current">
                                <div class="paging_node">
                                    <a href="' . $url_path . ($i > 1 ? '&' . $page_name . '=' . $i : '') . '">' . $i . '</a>
                                </div>
                        	</div>';
            } else {
                $paging_str .= '<div class="floatLeft  paging_bg" onmouseover="javascript:this.className=\'floatLeft  paging_bg_hover\'" onmouseout="javascript:this.className=\'floatLeft  paging_bg\'">
                                <div class="paging_node">
                                    <a  href="' . $url_path . ($i > 1 ? '&' . $page_name . '=' . $i : '') . '">' . $i . '</a>
                                </div>
                        </div>';
            }
        }

        $j = 8;
        while ($j <= 10) {
            if ($i <= $j && $i <= 10) {
                $paging_str .= '<div class="floatLeft  paging_bg" onmouseover="javascript:this.className=\'floatLeft  paging_bg_hover\'" onmouseout="javascript:this.className=\'floatLeft  paging_bg\'">
									<div class="paging_node">
										<a  href="' . $url_path . '&' . $page_name . '=' . $j . '">' . $j . '</a>
									</div>
							</div>';
                if ($i < 10) {
                    $i++;
                }
            }
            $j++;
        }

        if ($i > 201) {
            $paging_str .= '<div class="floatLeft  paging_bg" onmouseover="javascript:this.className=\'floatLeft  paging_bg_hover\'" onmouseout="javascript:this.className=\'floatLeft  paging_bg\'">
								<div class="paging_node">
									<a  href="' . $url_path . '&' . $page_name . '=200">200</a>
								</div>
						</div>';
        } elseif ($i < 201) {
            $paging_str .= '<div class="floatLeft  paging_bg">
								<div class="paging_node_dot">
									...
								</div>
						</div>';
        }

        //Trang sau
        if ($currentpage < 200) {
            $paging_str .= '<div class="paging_bg floatLeft " onmouseout="this.className=\'paging_bg floatLeft \'" onmouseover="this.className=\'paging_bg_hover floatLeft \'">
				<div class="paging_next">
					<a href=\'' . $url_path . '&' . $page_name . '=' . ($currentpage + 1) . '\'>Sau &raquo;</a>
				</div>
			</div>';
        } else {
            $paging_str .= '<div class="paging_bg_dis floatLeft ">
							<div class="paging_next_dis">
								Sau &raquo;
							</div>
				 		</div>';
        }

        $paging_str = ECRewrite::formatUrl($paging_str);

        return $paging_str;
    }

    static function paging_profile(&$limit = false, $totalitem, $itemperpage, $numpageshow = 10, $show_total_item = false, $page_name = "page_no", $url_path = "")
    {

        $totalpage = ceil($totalitem / $itemperpage);

        if ($totalpage < 2) {
            if ($show_total_item) {
                return '<b>Tổng số ' . $totalitem . '</b> ' . $itemname;
            }
            return;
        }

        if (Url::get($page_name)) {
            $currentpage = Url::get($page_name);
        } else {
            $currentpage = 1;
        }

        $currentpage = round($currentpage);
        if ($currentpage <= 0 || $currentpage > $totalpage) {
            $currentpage = 1;
        }

        $limit = ' LIMIT ' . (($currentpage - 1) * $itemperpage) . ',' . $itemperpage;

        if ($currentpage > ($numpageshow / 2)) {
            $startpage = $currentpage - floor($numpageshow / 2);
            if ($totalpage - $startpage < $numpageshow) {
                $startpage = $totalpage - $numpageshow + 1;
            }
        } else {
            $startpage = 1;
        }
        if ($startpage < 1) {
            $startpage = 1;
        }

        if ($url_path == '') {
            $url_path = Url::build_all(array($page_name));
        }

        //Link den trang truoc
        if ($currentpage > 1) {
            if (ECPaging::$page_current == "item_phone") {
                $page_no = $currentpage > 2 ? "&page_no=" . ($currentpage - 1) : "";
            } else {
                $page_no = $currentpage > 2 ? "/page-" . ($currentpage - 1) . ".html" : ".html";
            }
            $paging_str = '<div class="paging_bg floatLeft" onmouseout="this.className=\'paging_bg floatLeft\'" onmouseover="this.className=\'paging_bg_hover floatLeft\'">
						<div class="paging_pre">
							<a href=\'' . $url_path . $page_no . '\'>&laquo; Trước</a>
						</div>
					</div>';
        } else {
            $paging_str = '<div class="paging_bg_dis floatLeft ">
							<div class="paging_pre_dis">
									&laquo; Trước
							</div>
			 				</div>';
        }

        //Danh sach cac trang
        for ($i = $startpage; $i <= $totalpage; $i++) {
            if ($i == $currentpage) {

                if (ECPaging::$page_current == "item_phone") {
                    $page_no = ($i > 1 ? '&page_no=' . $i : '');
                } else {
                    $page_no = ($i > 1 ? '/page-' . $i . '.html' : '.html');
                }

                $paging_str .= '<div class="floatLeft paging_bg_hover paging_bg_current">
                                <div class="paging_node">
                                    <a href="' . $url_path . $page_no . '">' . $i . '</a>
                                </div>
                        	</div>';
            } else {
                if (ECPaging::$page_current == "item_phone") {
                    $page_no = ($i > 1 ? '&page_no=' . $i : '');
                } else {
                    $page_no = ($i > 1 ? '/page-' . $i . '.html' : '.html');
                }
                $paging_str .= '<div class="floatLeft  paging_bg" onmouseover="javascript:this.className=\'floatLeft  paging_bg_hover\'" onmouseout="javascript:this.className=\'floatLeft  paging_bg\'">
                                <div class="paging_node">
                                    <a  href="' . $url_path . $page_no . '">' . $i . '</a>
                                </div>
                        </div>';
            }
        }

        //Trang sau
        if ($currentpage < $totalpage) {
            if (ECPaging::$page_current == "item_phone") {
                $page_no = ($i > 1 ? '&page_no=' . $i : '');
            } else {
                $page_no = "/page-" . ($currentpage + 1) . ".html";
            }

            $paging_str .= '<div class="paging_bg floatLeft " onmouseout="this.className=\'paging_bg floatLeft \'" onmouseover="this.className=\'paging_bg_hover floatLeft \'">
				<div class="paging_next">
					<a href=\'' . $url_path . $page_no . '\'>Sau &raquo;</a>
				</div>
			</div>';
        } else {
            $paging_str .= '<div class="paging_bg_dis floatLeft ">
							<div class="paging_next_dis">
								Sau &raquo;
							</div>
				 		</div>';
        }

        $paging_str = ECRewrite::formatUrl($paging_str);

        return $paging_str;
    }

    static function AjaxPaging(&$limit = '', $totalitem, $itemperpage, $numpageshow = 10, $page_name = 'page_no', $page_label = 'Trang', $show_total_item = false, $itemname = 'mục', $url_path = '', $div_id = '', $show_list_page = false)
    {
        $st = '';
        $totalpage = ceil($totalitem / $itemperpage);
        if ($totalpage < 2) {
            return;
        }

        if (Url::get($page_name)) {
            $currentpage = Url::get($page_name);
        } else {
            $currentpage = 1;
        }

        $currentpage = round($currentpage);
        if ($currentpage <= 0 || $currentpage > $totalpage) {
            $currentpage = 1;
        }

        $limit = ' LIMIT ' . (($currentpage - 1) * $itemperpage) . ',' . $itemperpage;

        if ($currentpage > ($numpageshow / 2)) {
            $startpage = $currentpage - floor($numpageshow / 2);
            if ($totalpage - $startpage < $numpageshow) {
                $startpage = $totalpage - $numpageshow + 1;
            }
        } else {
            $startpage = 1;
        }
        if ($startpage < 1) {
            $startpage = 1;
        }

        if ($url_path != '')
            $url_path .= '&' . $page_name . '=';
        else
            $url_path = '?' . $page_name . '=';

        //Trang hien thoi
        $st .= '' . ($show_total_item ? 'T&#7893;ng c&#243; ' . $totalitem . ' ' . $itemname . ' | ' : '') . '' . $page_label . ' ';

        if ($show_list_page) {
            //Link den trang truoc
            if ($currentpage > 1) {


                $st .= '<div class="pag_bg floatLeft" onmouseout="this.className=\'pag_bg floatLeft\'" onmouseover="this.className=\'pag_bg_hover floatLeft\'" onclick="ajax_paging(\'' . $url_path . ($currentpage - 1) . '\',\'' . $div_id . '\',\'' . $url_path . $currentpage . '\'); return false;">
						<div class="pag_left_pre">
							<div class="pag_right_pre">
								<a href="javascript:void(0)" style="color:#ffffff">Trước</a>
							</div>
						</div>
					</div>';
            } else {
                $st .= '<div class="pag_bg_dis floatLeft ">
			<div class="pag_left_pre_dis">
				<div class="pag_right_pre_dis">
					Trước
				</div>
			</div>

			 </div>';
            }
            //Danh sach cac trang
            if ($startpage > 1) {

                $st .= '<div class="floatLeft  pag_bg" onmouseover="javascript:this.className=\'floatLeft  pag_bg_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg\'"  onclick = "ajax_paging(\'' . $url_path . '1\',\'' . $div_id . '\',\'' . $url_path . $currentpage . '\'); return false;">
							<div class="pag_left">
								<div class="pag_right">
									<a href="javascript:void(0);">1</a>
								</div>
							</div>
						</div>';


                if ($startpage > 2) {
                    $st .= '<div class="floatLeft  pag_bg">
							<div class="pag_left">
								<div class="pag_right_dot">
									...
								</div>
							</div>
						</div>';
                }
            }

            for ($i = $startpage; $i <= $startpage + $numpageshow - 1 && $i <= $totalpage; $i++) {
                /*if($i!=$startpage){$st .= '';}*/
                if ($i == $currentpage) {
                    /*if($i>1){$st .='';}*/

                    $st .= '<div class="floatLeft  pag_bg_hover">
							<div class="pag_left">
								<div class="pag_right">
									<a href="javascript:void(0);">' . $i . '</a>
								</div>
							</div>
						</div>';
                } else {
                    /*if($i>1){$st .='';}*/
                    $st .= '<div class="floatLeft  pag_bg" onmouseover="javascript:this.className=\'floatLeft  pag_bg_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg\'" onclick = "ajax_paging(\'' . $url_path . $i . '\',\'' . $div_id . '\',\'' . $url_path . $currentpage . '\'); return false;">
							<div class="pag_left">
								<div class="pag_right">
									<a href="javascript:void(0);" >' . $i . '</a>
								</div>
							</div>
						</div>';
                }
            }
            if ($i == $totalpage) {

                $st .= '<div class="floatLeft  pag_bg" onmouseover="javascript:this.className=\'floatLeft  pag_bg_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg\'" onclick = "ajax_paging(\'' . $url_path . $totalpage . '\',\'' . $div_id . '\',\'' . $url_path . $currentpage . '\'); return false;">
							<div class="pag_left">
								<div class="pag_right">
									<a  href="javascript:void(0);" >' . $totalpage . '</a>
								</div>
							</div>
						</div>';

            } elseif ($i < $totalpage) {
                $st .= '<div class="floatLeft  pag_bg">
							<div class="pag_left">
								<div class="pag_right_dot">
									...
								</div>
							</div>
						</div>


						<div class="floatLeft  pag_bg" onmouseover="javascript:this.className=\'floatLeft  pag_bg_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg\'" onclick = "ajax_paging(\'' . $url_path . $totalpage . '\',\'' . $div_id . '\',\'' . $url_path . $currentpage . '\'); return false;">
							<div class="pag_left">
								<div class="pag_right">
									<a  href="javascript:void(0);" >' . $totalpage . '</a>
								</div>
							</div>
						</div>

						';

            }
            //Trang sau
            if ($currentpage < $totalpage) {

                $st .= '<div class="pag_bg floatLeft " onmouseout="this.className=\'pag_bg floatLeft \'" onmouseover="this.className=\'pag_bg_hover floatLeft \'" onclick="ajax_paging(\'' . $url_path . ($currentpage + 1) . '\',\'' . $div_id . '\',\'' . $url_path . $currentpage . '\'); return false;">
			<div class="pag_left_next">
				<div class="pag_right_next">
					<a href="javascript:void(0);" style="color:#ffffff">Sau</a>
				</div>
			</div>
			</div>';

            } else {
                $st .= '<div class="pag_bg_dis floatLeft ">
						<div class="pag_left_next_dis">
							<div class="pag_right_next_dis">
								Sau
							</div>
						</div>
			 </div>';
            }
        } else { // neu khong co list so
            //Link den trang truoc
            if ($currentpage > 1) {


                $st .= '<div class="pag_bg floatLeft" onmouseout="this.className=\'pag_bg floatLeft\'" onmouseover="this.className=\'pag_bg_hover floatLeft\'" onclick="ajax_paging(\'' . $url_path . ($currentpage - 1) . '\',\'' . $div_id . '\',\'' . $url_path . $currentpage . '\'); return false;">
						<div class="pag_left_pre">
							<div class="pag_right_pre">
								<a href="javascript:void(0)" style="color:#ffffff">Trước</a>
							</div>
						</div>
					</div>';
            } else {
                $st .= '<div class="pag_bg_dis floatLeft ">
			<div class="pag_left_pre_dis">
				<div class="pag_right_pre_dis">
					Trước
				</div>
			</div>

			 </div>';
            }
            //Trang sau
            if ($currentpage < $totalpage) {

                $st .= '<div class="pag_bg floatLeft " onmouseout="this.className=\'pag_bg floatLeft \'" onmouseover="this.className=\'pag_bg_hover floatLeft \'" onclick="ajax_paging(\'' . $url_path . ($currentpage + 1) . '\',\'' . $div_id . '\',\'' . $url_path . $currentpage . '\'); return false;">
			<div class="pag_left_next">
				<div class="pag_right_next">
					<a href="javascript:void(0);" style="color:#ffffff">Sau</a>
				</div>
			</div>
			</div>';

            } else {
                $st .= '<div class="pag_bg_dis floatLeft ">
						<div class="pag_left_next_dis">
							<div class="pag_right_next_dis">
								Sau
							</div>
						</div>
			 </div>';
            }
        }
        return $st;
    }

    static function AjaxPagingNext(&$limit = '', $itemperpage, $next_page = false, $page_name = 'page_no', $url_path = '', $div_id = '')
    {
        $st = '';

        if (Url::get($page_name)) {
            $currentpage = (int)Url::get($page_name);
        } else {
            $currentpage = 1;
        }

        if ($currentpage <= 0) {
            $currentpage = 1;
        }

        $limit = ' LIMIT ' . (($currentpage - 1) * $itemperpage) . ',' . ($itemperpage + 1);

        if ($url_path != '')
            $url_path .= '&' . $page_name . '=';
        else
            $url_path = '?' . $page_name . '=';

        //Link den trang truoc
        if ($currentpage > 1) {
            $st .= '<div class="pag_bg floatLeft" onmouseout="this.className=\'pag_bg floatLeft\'" onmouseover="this.className=\'pag_bg_hover floatLeft\'" onclick="ajax_paging(\'' . $url_path . ($currentpage - 1) . '\',\'' . $div_id . '\',\'' . $url_path . $currentpage . '\'); return false;">
					<div class="pag_left_pre">
						<div class="pag_right_pre">
							<a href="javascript:void(0)" style="color:#ffffff">Trước</a>
						</div>
					</div>
				</div>';
        } else {
            $st .= '<div class="pag_bg_dis floatLeft ">
					<div class="pag_left_pre_dis">
						<div class="pag_right_pre_dis">
							Trước
						</div>
					</div>

					 </div>';
        }

        //Trang sau
        if ($next_page) {
            $st .= '<div class="pag_bg floatLeft " onmouseout="this.className=\'pag_bg floatLeft \'" onmouseover="this.className=\'pag_bg_hover floatLeft \'" onclick="ajax_paging(\'' . $url_path . ($currentpage + 1) . '\',\'' . $div_id . '\',\'' . $url_path . $currentpage . '\'); return false;">
					<div class="pag_left_next">
						<div class="pag_right_next">
							<a href="javascript:void(0);" style="color:#ffffff">Sau</a>
						</div>
					</div>
					</div>';

        } else {
            $st .= '<div class="pag_bg_dis floatLeft ">
					<div class="pag_left_next_dis">
						<div class="pag_right_next_dis">
							Sau
						</div>
					</div>
		 </div>';
        }
        return $st;
    }


    static function AjaxPagingNextCat(&$limit = '', $itemperpage, $next_page = false, $page_name = 'page_no', $url_path = '', $div_id = '')
    {
        $st = '';

        if (Url::get($page_name)) {
            $currentpage = (int)Url::get($page_name);
        } else {
            $currentpage = 1;
        }

        if ($currentpage <= 0) {
            $currentpage = 1;
        }

        $limit = ' LIMIT ' . (($currentpage - 1) * $itemperpage) . ',' . ($itemperpage);

        if ($url_path != '')
            $url_path .= '&' . $page_name . '=';
        else
            $url_path = '?' . $page_name . '=';

        //Link den trang truoc
        if ($currentpage > 1) {
            $st .= '<div class="pag_bg floatLeft" onmouseout="this.className=\'pag_bg floatLeft\'" onmouseover="this.className=\'pag_bg_hover floatLeft\'" onclick="ajax_paging(\'' . $url_path . ($currentpage - 1) . '\',\'' . $div_id . '\',\'' . $url_path . $currentpage . '\'); return false;">
					<div class="pag_left_pre">
						<div class="pag_right_pre">
							<a href="javascript:void(0)" style="color:#ffffff">Trước</a>
						</div>
					</div>
				</div>';
        } else {
            $st .= '<div class="pag_bg_dis floatLeft ">
					<div class="pag_left_pre_dis">
						<div class="pag_right_pre_dis">
							Trước
						</div>
					</div>

					 </div>';
        }

        //Trang sau
        if ($next_page) {
            $st .= '<div class="pag_bg floatLeft " onmouseout="this.className=\'pag_bg floatLeft \'" onmouseover="this.className=\'pag_bg_hover floatLeft \'" onclick="ajax_paging(\'' . $url_path . ($currentpage + 1) . '\',\'' . $div_id . '\',\'' . $url_path . $currentpage . '\'); return false;">
					<div class="pag_left_next">
						<div class="pag_right_next">
							<a href="javascript:void(0);" style="color:#ffffff">Sau</a>
						</div>
					</div>
					</div>';

        } else {
            $st .= '<div class="pag_bg_dis floatLeft ">
					<div class="pag_left_next_dis">
						<div class="pag_right_next_dis">
							Sau
						</div>
					</div>
		 </div>';
        }
        return $st;
    }

    static function fb_pagging(&$limit = '', $itemperpage, $next_page = false, $page_name = 'page_no', $url_path = '', $div_id = '')
    {
        $st = '';

        if (Url::get($page_name)) {
            $currentpage = (int)Url::get($page_name);
        } else {
            $currentpage = 1;
        }

        if ($currentpage <= 0) {
            $currentpage = 1;
        }

        $limit = ' LIMIT ' . (($currentpage - 1) * $itemperpage) . ',' . ($itemperpage + 1);

        if ($url_path != '')
            $url_path .= '&' . $page_name . '=';
        else
            $url_path = '?' . $page_name . '=';

        //Link den trang truoc
        if ($currentpage > 1) {
            $st .= '<div class="pag_bg floatLeft" onmouseout="this.className=\'pag_bg floatLeft\'" onmouseover="this.className=\'pag_bg_hover floatLeft\'" onclick="fb_paging(\'' . $url_path . ($currentpage - 1) . '\',\'' . $div_id . '\',\'' . $url_path . $currentpage . '\'); return false;">
					<div class="pag_left_pre">
						<div class="pag_right_pre">
							<a href=\'javascript:void(0)\'>Trước</a>
						</div>
					</div>
				</div>';
        } else {
            $st .= '<div class="pag_bg_dis floatLeft ">
					<div class="pag_left_pre_dis">
						<div class="pag_right_pre_dis">
							Trước
						</div>
					</div>

					 </div>';
        }

        //Trang sau
        if ($next_page) {
            $st .= '<div class="pag_bg floatLeft " onmouseout="this.className=\'pag_bg floatLeft \'" onmouseover="this.className=\'pag_bg_hover floatLeft \'" onclick="fb_paging(\'' . $url_path . ($currentpage + 1) . '\',\'' . $div_id . '\',\'' . $url_path . $currentpage . '\'); return false;">
					<div class="pag_left_next">
						<div class="pag_right_next">
							<a href="javascript:void(0);">Sau</a>
						</div>
					</div>
					</div>';

        } else {
            $st .= '<div class="pag_bg_dis floatLeft ">
					<div class="pag_left_next_dis">
						<div class="pag_right_next_dis">
							Sau
						</div>
					</div>
		 </div>';
        }
        return $st;
    }


    static function pagingSearch(&$limit = false, $totalitem, $itemperpage, $numpageshow = 10, $page_name = 'page-no', $show_total_item = false, $itemname = '', $url = '', $page_no = 1, $mod = false)
    {
        $st = '';
        $totalpage = ceil($totalitem / $itemperpage);
        if ($totalpage < 2) {
            if ($show_total_item) {
                return '';
            }
            return;
        }

        if (Url::get($page_name)) {
            $currentpage = Url::get($page_name);
        } else {
            $currentpage = $page_no;
        }

        $currentpage = round($currentpage);
        if ($currentpage <= 0 || $currentpage > $totalpage) {
            $currentpage = 1;
        }

        $limit = ' LIMIT ' . (($currentpage - 1) * $itemperpage) . ',' . $itemperpage;

        if ($currentpage > ($numpageshow / 2)) {
            $startpage = $currentpage - floor($numpageshow / 2);
            if ($totalpage - $startpage < $numpageshow) {
                $startpage = $totalpage - $numpageshow + 1;
            }
        } else {
            $startpage = 1;
        }
        if ($startpage < 1) {
            $startpage = 1;
        }
        if ($url == '') {
            $url_path = Url::build_all(array($page_name));
        } else {
            $url_path = WEB_ROOT . $url;
        }


        //Trang hien thoi
        // $st .= ''.($show_total_item?'<b>Tổng số '.number_format($totalitem, 0, '', '.').' '.$itemname.'</b> | ':'').''.$page_label.' ';
        //Link den trang truoc
        if ($currentpage > 1) {
            $st .= '<a href="' . $url_path . '&page_no=' . ($currentpage - 1) . '" class="pgPrev sys-paging-location">';
            $st .= 'Trước</a>';
        }

        //Danh sach cac trang
        $st .= '';

        if ($startpage > 1) {
            //$st .= '<a href="'.$url_path.(strpos($url_path, '?')===false?'?':'&').$page_name.'='.$currentpage.'" id="pgNext">';
            $st .= '<a  href="' . $url_path . '&page_no=1" class="sys-paging-location">1</a> ';
            if ($startpage > 2) {
                $st .= '<strong>...</strong>'; //
            }
        }

        for ($i = $startpage; $i <= $startpage + $numpageshow - 1 && $i <= $totalpage; $i++) {
            if ($i != $startpage) {
                $st .= ''; //
            }
            if ($i == $currentpage) {
                if ($i > 1) {
                    $st .= '';
                }
                $st .= '<a href="' . $url_path . '&page_no=' . $i . '" class="pgCurrent current sys-paging-location" id="pgCurrent" style="color:red;">' . $i . '</a>';
            } else {
                if ($i > 1) {
                    $st .= '';
                }
                $st .= '<a  href="' . $url_path . '&page_no=' . $i . '" class="sys-paging-location">' . $i . '</a> ';
            }
        }

        if ($i == $totalpage) {
            $st .= '<a  href="' . $url_path . '&page_no=' . $totalpage . '" class="sys-paging-location">' . $totalpage . '</a> ';
        } else
            if ($i < $totalpage) {
                $st .= '<strong>...</strong><a  href="' . $url_path . '&page_no=' . $totalpage . '" class="sys-paging-location">' . $totalpage . '</a> ';
            }
        $st .= '';
        //Trang sau
        if ($currentpage < $totalpage) {
            $st .= '<a  href="' . $url_path . '&page_no=' . ($currentpage + 1) . '" class="pgPrev sys-paging-location">';
            $st .= 'Sau</a>';
        }

        $st .= '';

        $st = ECRewrite::formatUrl($st);
        return "<div class=\"paging-hotel sys-paging-location-hotel\">$st</div>";
    }

    static function pagingnews(&$limit = false, $totalitem, $itemperpage, $numpageshow = 10, $page_name = 'page_no', $show_total_item = false, $itemname = '', $page_label = '', $mod = false)
    {
        $totalpage = ceil($totalitem / $itemperpage);
        if ($totalpage < 2) {
            return;
        }
        if (Url::get($page_name)) {
            $currentpage = Url::get($page_name);
        } else {
            $currentpage = 1;
        }

        $currentpage = round($currentpage);
        if ($currentpage <= 0 || $currentpage > $totalpage) {
            $currentpage = 1;
        }

        $limit = ' LIMIT ' . (($currentpage - 1) * $itemperpage) . ',' . $itemperpage;

        if ($currentpage > ($numpageshow / 2)) {
            $startpage = $currentpage - floor($numpageshow / 2);
            if ($totalpage - $startpage < $numpageshow) {
                $startpage = $totalpage - $numpageshow + 1;
            }
        } else {
            $startpage = 1;
        }
        if ($startpage < 1) {
            $startpage = 1;
        }

        if (strpos(Url::build_all(array($page_name)), "?") !== false) {
            $url_path = Url::build_all(array($page_name)) . '&' . $page_name . '=';
        } else {
            $url_path = Url::build_all(array($page_name)) . '?' . $page_name . '=';
        }

        //Link den trang truoc
        if ($currentpage > 1) {
            $st = '<div class="pag_bg2 floatLeft" onmouseout="this.className=\'pag_bg2 floatLeft\'" onmouseover="this.className=\'pag_bg2_hover floatLeft\'">
						<div class="pag_left_pre2">
							<div class="pag_right_pre">
								<a href=\'' . $url_path . ($currentpage - 1) . '\'>Trước</a>
							</div>
						</div>
					</div>';
        } else {
            $st = '<div class="pag_bg2_dis floatLeft ">
			<div class="pag_left_pre2_dis">
				<div class="pag_right_pre_dis">
					Trước
				</div>
			</div>

			 </div>';
        }
        //Danh sach cac trang
        if ($startpage > 1) {
            $st .= '<div class="floatLeft  pag_bg2" onmouseover="javascript:this.className=\'floatLeft  pag_bg2_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg2\'">
							<div class="pag_left">
								<div class="pag_right">
									<a  href="' . $url_path . '1">1</a>
								</div>
							</div>
						</div>
					';
            if ($startpage > 2) {
                //$st .= '<div class="floatLeft marginLeft5" style="border:1px solid #f00"><strong>...</strong></div>';

                $st .= '<div class="floatLeft  pag_bg2">
							<div class="pag_left">
								<div class="pag_right_dot">
									...
								</div>
							</div>
						</div>';
            }
        }

        for ($i = $startpage; $i <= $startpage + $numpageshow - 1 && $i <= $totalpage; $i++) {
            /*if($i!=$startpage){$st .= '';}*/
            if ($i == $currentpage) {
                /*if($i>1){$st .='';}*/
                $st .= '<div class="floatLeft  pag_bg2_hover" style="border:1px #C3C2C2 solid; margin-top: -2px;">
							<div class="pag_left">
								<div class="pag_right">
									<a href="javascript:void(0);" style="cursor:default; color: #999999">' . $i . '</a>
								</div>
							</div>
						</div>';
            } else {
                /*if($i>1){$st .='';}*/
                $st .= '<div class="floatLeft  pag_bg2" onmouseover="javascript:this.className=\'floatLeft  pag_bg2_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg2\'">
							<div class="pag_left">
								<div class="pag_right">
									<a  href="' . $url_path . $i . '">' . $i . '</a>
								</div>
							</div>
						</div>';
            }
        }
        if ($i == $totalpage) {
            $st .= '<div class="floatLeft  pag_bg2" onmouseover="javascript:this.className=\'floatLeft  pag_bg2_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg2\'">
							<div class="pag_left">
								<div class="pag_right">
									<a  href="' . $url_path . $totalpage . '">' . $totalpage . '</a>
								</div>
							</div>
						</div>';

        } elseif ($i < $totalpage) {
            $st .= '<div class="floatLeft  pag_bg2">
							<div class="pag_left">
								<div class="pag_right_dot">
									...
								</div>
							</div>
						</div>
					<div class="floatLeft  pag_bg2" onmouseover="javascript:this.className=\'floatLeft  pag_bg2_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg2\'">
							<div class="pag_left">
								<div class="pag_right">
									<a  href="' . $url_path . $totalpage . '">' . $totalpage . '</a>
								</div>
							</div>
						</div>';
        }
        //Trang sau
        if ($currentpage < $totalpage) {
            $st .= '<div class="pag_bg2 floatLeft " onmouseout="this.className=\'pag_bg2 floatLeft \'" onmouseover="this.className=\'pag_bg2_hover floatLeft \'">
			<div class="pag_left_next2">
				<div class="pag_right_next2">
					<a href=\'' . $url_path . ($currentpage + 1) . '\'>Sau</a>
				</div>
			</div>
			</div>';
        } else {
            $st .= '<div class="pag_bg2_dis floatLeft ">
						<div class="pag_left_next2_dis">
							<div class="pag_right_next2_dis">
								Sau
							</div>
						</div>
			 </div>';
        }

        $st = ECRewrite::formatUrl($st);
        return $st;
    }

    static function pagingnews2(&$limit = false, $alias, $totalitem, $itemperpage, $numpageshow = 10, $page_name = 'page_no', $show_total_item = false, $itemname = '', $page_label = '', $mod = false)
    {
        $totalpage = ceil($totalitem / $itemperpage);
        if ($totalpage < 2) {
            return;
        }
        if (Url::get($page_name)) {
            $currentpage = Url::get($page_name);

        } else {
            $currentpage = 1;
        }

        $currentpage = round($currentpage);
        if ($currentpage <= 0 || $currentpage > $totalpage) {
            $currentpage = 1;
        }

        $limit = ' LIMIT ' . (($currentpage - 1) * $itemperpage) . ',' . $itemperpage;

        if ($currentpage > ($numpageshow / 2)) {
            $startpage = $currentpage - floor($numpageshow / 2);
            if ($totalpage - $startpage < $numpageshow) {
                $startpage = $totalpage - $numpageshow + 1;
            }
        } else {
            $startpage = 1;
        }
        if ($startpage < 1) {
            $startpage = 1;
        }

        /*if(strpos(Url::build_all(array($page_name)),"?")!==false){
            $url_path = Url::build_all(array($page_name)).'&'.$page_name.'=';
        }else{
            $url_path = Url::build_all(array($page_name)).'?'.$page_name.'=';
        }*/
//        var_dump(Url::build_all(array($page_name)));
        $cat = Url::get('cat');
        $url_path = 'du-lich/' . $alias . '-' . $cat;
        //Link den trang truoc
        if ($currentpage > 1) {
            if ($currentpage == 2) {
                $st = '<div class="pag_bg2 floatLeft" onmouseout="this.className=\'pag_bg2 floatLeft\'" onmouseover="this.className=\'pag_bg2_hover floatLeft\'">
						<div class="pag_left_pre2">
							<div class="pag_right_pre">
								<a href=\'' . $url_path . '\'>Trước</a>
							</div>
						</div>
					</div>';
            } else {

                $st = '<div class="pag_bg2 floatLeft" onmouseout="this.className=\'pag_bg2 floatLeft\'" onmouseover="this.className=\'pag_bg2_hover floatLeft\'">
						<div class="pag_left_pre2">
							<div class="pag_right_pre">
								<a href=\'' . $url_path . '/page' . ($currentpage - 1) . '\'>Trước</a>
							</div>
						</div>
					</div>';
            }
        } else {
            $st = '<div class="pag_bg2_dis floatLeft ">
			<div class="pag_left_pre2_dis">
				<div class="pag_right_pre_dis">
					Trước
				</div>
			</div>

			 </div>';
        }
        //Danh sach cac trang
        if ($startpage > 1) {
            $st .= '<div class="floatLeft  pag_bg2" onmouseover="javascript:this.className=\'floatLeft  pag_bg2_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg2\'">
							<div class="pag_left">
								<div class="pag_right">
									<a  href="' . $url_path . '/page' . '1">1</a>
								</div>
							</div>
						</div>
					';
            if ($startpage > 2) {
                //$st .= '<div class="floatLeft marginLeft5" style="border:1px solid #f00"><strong>...</strong></div>';

                $st .= '<div class="floatLeft  pag_bg2">
							<div class="pag_left">
								<div class="pag_right_dot">
									...
								</div>
							</div>
						</div>';
            }
        }

        for ($i = $startpage; $i <= $startpage + $numpageshow - 1 && $i <= $totalpage; $i++) {
            /*if($i!=$startpage){$st .= '';}*/
            if ($i == $currentpage) {
                /*if($i>1){$st .='';}*/
                $st .= '<div class="floatLeft  pag_bg2_hover">
							<div class="pag_left">
								<div class="pag_right" style="border:1px #C3C2C2 solid; margin-top: -2px;">
									<a href="javascript:void(0);" style="cursor:default; color: #999999">' . $i . '</a>
								</div>
							</div>
						</div>';
            } else {
                if ($i == 1) {
                    $st .= '<div class="floatLeft  pag_bg2" onmouseover="javascript:this.className=\'floatLeft  pag_bg2_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg2\'">
							<div class="pag_left">
								<div class="pag_right">
									<a  href="' . $url_path .'">' . $i . '</a>
								</div>
							</div>
						</div>';
                } else {
                /*if($i>1){$st .='';}*/
                $st .= '<div class="floatLeft  pag_bg2" onmouseover="javascript:this.className=\'floatLeft  pag_bg2_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg2\'">
							<div class="pag_left">
								<div class="pag_right">
									<a  href="' . $url_path . '/page' . $i . '">' . $i . '</a>
								</div>
							</div>
						</div>';
                }
            }
        }
        if ($i == $totalpage) {
            $st .= '<div class="floatLeft  pag_bg2" onmouseover="javascript:this.className=\'floatLeft  pag_bg2_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg2\'">
							<div class="pag_left">
								<div class="pag_right">
									<a  href="' . $url_path . '/page' . $totalpage . '">' . $totalpage . '</a>
								</div>
							</div>
						</div>';

        } elseif ($i < $totalpage) {
            $st .= '<div class="floatLeft  pag_bg2">
							<div class="pag_left">
								<div class="pag_right_dot">
									...
								</div>
							</div>
						</div>
					<div class="floatLeft  pag_bg2" onmouseover="javascript:this.className=\'floatLeft  pag_bg2_hover\'" onmouseout="javascript:this.className=\'floatLeft  pag_bg2\'">
							<div class="pag_left">
								<div class="pag_right">
									<a  href="' . $url_path . '/page' . $totalpage . '">' . $totalpage . '</a>
								</div>
							</div>
						</div>';
        }
        //Trang sau
        if ($currentpage < $totalpage) {
            $st .= '<div class="pag_bg2 floatLeft " onmouseout="this.className=\'pag_bg2 floatLeft \'" onmouseover="this.className=\'pag_bg2_hover floatLeft \'">
			<div class="pag_left_next2">
				<div class="pag_right_next2">
					<a href=\'' . $url_path . '/page' . ($currentpage + 1) . '\'>Sau</a>
				</div>
			</div>
			</div>';
        } else {
            $st .= '<div class="pag_bg2_dis floatLeft ">
						<div class="pag_left_next2_dis">
							<div class="pag_right_next2_dis">
								Sau
							</div>
						</div>
			 </div>';
        }

        $st = ECRewrite::formatUrl($st);
        return $st;
    }
}

?>